/*******************************************************************************
 * Copyright (c) 2007 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.listener;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.EditPart;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.editpart.IUMLObjectEditPart;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * 
 * 
 * @author Patrick Tessier
 * @since 5 sept. 07
 * this class is used to create a listener on resource and to call automatically editPart.refresh
 * when the resource element is modified
 */

public class DiagramListener extends ObjectListener {

	private ModelManager modelManager;


	/**
	 * this class create a listener on the umlElement.
	 * 
	 * @param editPart the editpart of the resource
	 */
	public DiagramListener(IUMLObjectEditPart editPart, ModelManager modelManager){
		super(editPart);
		this.editPart=(EditPart)editPart;
		this.modelManager=modelManager;
	}

	/**
	 * {@inheritDoc}
	 */
	public void notifyChanged(Notification notification) {
		if (notification.getEventType() != Notification.REMOVING_ADAPTER) {
			editPart.refresh();	
			modelManager.modifGraphElement((GraphElement)notification.getNotifier());
		}
	}

}